﻿@model DAEProde.Domain.Ticket

@{
    ViewBag.Title = "ViewTicket";
}

<h1>@Model.MatchDate.Tournament.Name - Mi Boleta</h1>

<h3>Seleccione su pronostico haciendo click en local, visitante o empate.</h3>

<h4>Los pronosticos deben ser realizados 2 horas antes de que comience el primer partido.</h4>

<fieldset>
<legend>@Model.MatchDate.Name - @Model.MatchDate.Date.ToShortDateString()</legend>

<table>
    <tr>
        <th>
            Fecha Partido
        </th>
        <th>
            Equipo Local
        </th>
        <th>
            Equipo Visitante
        </th>
        <th>
            Realizar
        </th>
        <th>
            Mi Pronostico
        </th>
    </tr>

@foreach (var item in Model.Predictions) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Match.Date)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Match.LocalTeam.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Match.OutTeam.Name)
        </td>
            @if (item.Match.Date.Subtract(DateTime.Now).TotalHours > 2)
            {
                <td>
                    @Html.ActionLink("Local", "Actualizar", new { r = "Local", tId = Model.Id, pId = item.Id }) |
                    @Html.ActionLink("Empate", "Actualizar", new { r = "Empate", tId = Model.Id, pId = item.Id }) |
                    @Html.ActionLink("Visitante", "Actualizar", new { r = "Visitante", tId = Model.Id, pId = item.Id })            
                </td>
            }
            else
            {
                <td>
                    Time Out          
                </td>
            }
        <td>
            @Html.DisplayFor(modelItem => item.Will)
        </td>
    </tr>
}

</table>

<p>
    @Html.ActionLink("Ver Resultado Boleta", "ViewTicketResult", new { id = Model.Id })
</p>

</fieldset>

@using (Html.BeginForm("ChangeMatchDate", "Ticket"))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Cambiar Fecha</legend>

        @Html.Hidden("id", Model.MatchDate.Tournament.Id)

        <div class="editor-label">
            @Html.LabelFor(m => m.MatchDate)
        </div>
        <div class="editor-field">
            <!-- Manually creating dropdown because ASP.NET MVC won't handle selected-value correctly, IMO -->
            <!-- This would be a good item for a helper, which is beyond the scope of this sample. -->
            <select name="fId">
                @foreach (var matchDate in Model.MatchDate.Tournament.MatchDates)
                {
                    <option value="@matchDate.Id" @(matchDate.Equals(Model.MatchDate) ? "selected=\"selected\"" : "")>@matchDate.Name - @matchDate.Date.ToShortDateString()</option>
                }
            </select>
            @Html.ValidationMessageFor(m => m.MatchDate)
        </div>

        <p>
            <input type="submit" value="Ver Fecha" />
        </p>
    </fieldset>
}